package org.bite.lesson10;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 原子类
 */
public class Demo1002 {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger();
        //获取当前的值
        System.out.println(atomicInteger.get());
        //自增i++
        atomicInteger.getAndIncrement();
        System.out.println(atomicInteger.get());
        System.out.println(atomicInteger.getAndIncrement());
        System.out.println(atomicInteger.get());
        //自增++i
        atomicInteger.incrementAndGet();
        System.out.println(atomicInteger.get());
        System.out.println(atomicInteger.incrementAndGet());
        //自减i--
        atomicInteger.getAndDecrement();
        System.out.println(atomicInteger.get());
        //自减--i
        System.out.println(atomicInteger.decrementAndGet());
        //累加 i+x
        atomicInteger.getAndAdd(5);
        System.out.println(atomicInteger.get());
        atomicInteger.getAndAdd(10);
        System.out.println(atomicInteger.get());
    }
}
